<script setup lang="ts">
import { onMounted, ref} from "vue";
import {getSysConfig, updateSysConfig} from "@/service/api";
import {localStg} from "@/utils/storage";

const token = ref<string>("");
const formModel = ref<any>({
  system_name: "",
  domain_name: "",
  ip_address: "",
  max_failed_login_attempts: "",
  password_lock_time: "",
  file_path: "",
  wx_pay_cert_sn: "",
  wx_pay_key_path: "",
  wx_pay_notify_url: "",
  wx_pay_apiv3: "",
  wx_pay_apiv2: "",
  wx_pay_mchid: "",
  wx_gz_secret: "",
  wx_gz_appid: "",
  wx_mp_secret: "",
  wx_mp_appid: "",
  deposit_times_am: "08:00:00",
  deposit_times_pm: "18:00:00",
  balance_limit: "",
  single_limit: "",
  daily_frequency: "",
  wxmp_index_images: "",
  wxmp_index_notice: "<p>hello</p>",
  RegEx_phoneNumber: "",
  RegEx_fullName: "",
  RegEx_IDCard: "",
  RegEx_CriminalSn: "",
  RegEx_CriminalFileSn: "",
});
//保存
async function handleSubmit() {
  let res = await updateSysConfig(formModel.value);
  if (res.error) {
  } else {
    window.$message?.success("保存成功");
    await getSysConfigData();
  }
}
//获取系统配置
async function getSysConfigData() {
  // wxmpIndexImagesList.value = [];
  let res = await getSysConfig({});
  if (res.error) {
  } else {
    let configList: Api.Entity.Config[] = res.data;
    configList.forEach((item: Api.Entity.Config) => {
      formModel.value[item.configKey] = item.configValue;
    });
  }
}
//挂载时获取token
onMounted(() => {
  getSysConfigData();
  token.value = localStg.get('token') || '';
});
</script>

<template>
  <div>
    <n-form ref="formRef" label-placement="left" :label-width="120" :model="formModel" >
      <n-grid :cols="24" :x-gap="10">
        <n-form-item-grid-item :span="12" label="小程序_appid" path="wx_mp_appid">
          <n-input v-model:value="formModel.wx_mp_appid"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="小程序_secret" path="wx_mp_secret">
          <n-input v-model:value="formModel.wx_mp_secret"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="公众号_appid" path="wx_gz_appid">
          <n-input v-model:value="formModel.wx_gz_appid"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="公众号_secret" path="wx_gz_secret">
          <n-input v-model:value="formModel.wx_gz_secret"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="商户号" path="wx_pay_mchid">
          <n-input v-model:value="formModel.wx_pay_mchid"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="商户号_apiv2" path="wx_pay_apiv2">
          <n-input v-model:value="formModel.wx_pay_apiv2"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="商户号_apiv3" path="wx_pay_apiv3">
          <n-input v-model:value="formModel.wx_pay_apiv3"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="商户号_回调地址" path="wx_pay_notify_url">
          <n-input v-model:value="formModel.wx_pay_notify_url"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="商户号_证书路径" path="wx_pay_key_path">
          <n-input v-model:value="formModel.wx_pay_key_path"/>
        </n-form-item-grid-item>
        <n-form-item-grid-item :span="12" label="商户号_证书序列号" path="wx_pay_cert_sn">
          <n-input v-model:value="formModel.wx_pay_cert_sn"/>
        </n-form-item-grid-item>
      </n-grid>
      <n-space class="w-full pt-16px" :size="24" justify="end">
        <n-button class="w-72px" type="primary" @click="handleSubmit">确定</n-button>
      </n-space>
    </n-form>
  </div>
</template>

<style scoped>

</style>
